<template>
	<view class="inventoryManagementMain">
		<view class="inventoryManagementBox">
			<view class="inventoryManagementHeader flex align-center justify-between">
				<view class="title flex align-center" v-if="type == 'HJ'">{{ name?name:'-----' }}<text>合作方</text></view>
				<view class="title flex align-center" v-if="type == 'BJ'">{{ name?name:'-----' }}<text>签约方</text></view>
			</view>
			<view class="oneBox">
				<view class="oneTop flex align-center justify-between">
					<view class="oneTopLeft">累计已激活(台)<text style="margin-top: 20rpx">{{
              randerData.totalActive
            }}</text></view>
					<view class="oneTopRight"><text>{{ activationRate }}%</text>累计激活率</view>
				</view>
				<view class="oneSub flex align-center justify-between">
					<view>总库存(台)</view>
					<view>{{ randerData.totalMachine }}</view>
				</view>
			</view>
			<view class="twoBox flex align-center justify-between">
				<view class="twoItem">
					<view>我的库存(台)</view>
					<view><text>{{ randerData.myMachine }}</text></view>
					<view>激活台数：<text>{{ randerData.myActive }}</text></view>
					<view>激活率：<text style="color:#f33;">{{personalRate}}%</text></view>
				</view>
				<view class="twoItem">
					<view>团队库存(台)</view>
					<view><text>{{ randerData.teamMachine }}</text></view>
					<view>激活台数：<text>{{ randerData.teamActive }}</text></view>
					<view>激活率：<text style="color:#f33;">{{teamRate}}%</text></view>
				</view>
			</view>
			<view class="threeBox flex align-center justify-between">
				<view class="threeItem" @click="activeDayTab">
					<view class="flex align-center">
						<text>今日激活:</text>
						<text>{{ randerData.todayActive }}</text>
					</view>

					<u-icon name="arrow-right" class="right" size="26"></u-icon>
				</view>
				<view class="threeItem" @click="activeMonthTab">
					<view class="flex align-center">
						<text>本月激活:</text>
						<text>{{ randerData.monthActive }}</text>
					</view>

					<u-icon name="arrow-right" class="right" size="26"></u-icon>
				</view>
			</view>
		</view>
		<toast></toast>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				queryData: {
					agent_id: "",
				},
				name: "",
				type: "",
				randerData: {
					myActive: "0",
					myMachine: "0",
					teamActive: "0",
					teamMachine: "0",
					totalActive: "0",
					totalMachine: "0",
					todayActive: "0",
					monthActive: "0",
				},
			};
		},
		computed: {
			activationRate() {
				let activationRate = "100";
				if (this.randerData.totalMachine != 0) {
					activationRate =
						(this.randerData.totalActive / this.randerData.totalMachine) * 100
					activationRate = activationRate.toFixed(2);
				}
				return activationRate;
			},
			personalRate() {
				let personalRate = "100";
				if (this.randerData.myMachine != 0) {
					personalRate =
						(this.randerData.myActive / this.randerData.myMachine) * 100
					personalRate = personalRate.toFixed(2);
				}
				return personalRate;
			},
			teamRate() {
				let teamRate = "100";
				if (this.randerData.teamMachine != 0) {
					teamRate =
						(this.randerData.teamActive / this.randerData.teamMachine) * 100
					teamRate = teamRate.toFixed(2);
				}
				return teamRate;
			}
		},
		onLoad(options) {
			this.name = options.name;
			this.agent_id = options.agent_id;
			this.type = options.type;
			this.getStockData();
		},
		onPullDownRefresh() {
			this.getStockData();
		},
		methods: {
			getStockData() {
				this.$u.api
					.getStockInfoByAgtId({
						agent_id: this.agent_id
					})
					.then((res) => {
						if (res.status == 200) {
							this.randerData = res.result;
						}
						uni.stopPullDownRefresh();
					})
					.catch((res) => {
						if (res.errMsg == "request:fail timeout") {
							this.$u.toast("请求超时，请重试!");
						} else if (res.errMsg == "request:fail") {
							this.$u.toast("请求失败，请重试");
						} else {
							this.$u.toast("请求失败，请重试");
						}
						this.$loading(false);
						setTimeout(() => {
							this.$u.route({
								type: "navigateBack",
								delta: 1,
							});
						}, 2000);
					});
			},

			activeDayTab() {
				this.$u.route({
					url: "/pages/myTeam/jhmx",
					params: {
						id: this.agent_id,
						searchType: 'day'
					},
				})
			},

			activeMonthTab() {
				this.$u.route({
					url: "/pages/myTeam/jhmx",
					params: {
						id: this.agent_id,
						searchType: 'month'
					},
				})
			}
		},
	};
</script>
<style lang="scss">
	page {
		background: #fff;
	}

	.inventoryManagementHeader {
		padding-bottom: 50rpx;

		.title {
			font-size: 40rpx;
			font-weight: bold;

			text {
				background: #f33;
				font-size: 24rpx;
				color: #fff;
				margin-left: 10rpx;
				line-height: 30rpx;
				width: 80rpx;
				text-align: center;
				display: block;
			}
		}
	}

	.inventoryManagementBox {
		padding: 50rpx 30rpx;

		.oneBox {
			.oneTop {
				margin-bottom: 40rpx;

				.oneTopLeft {
					font-size: 28rpx;
					font-weight: bold;
					position: relative;
					padding-left: 20rpx;

					&::before {
						content: "";
						display: block;
						width: 6rpx;
						height: 28rpx;
						background: #fb4535;
						position: absolute;
						left: 0;
						top: 6rpx;
					}

					text {
						display: block;
						font-size: 60rpx;
						font-weight: bold;
						font-family: "numberFont";
						letter-spacing: 4rpx;
						line-height: 60rpx;
					}
				}

				.oneTopRight {
					font-size: 28rpx;
					text-align: center;

					text {
						color: #fb4535;
						font-weight: bold;
						display: block;
						font-size: 40rpx;
						font-weight: bold;
						font-family: "numberFont";
						letter-spacing: 4rpx;
						line-height: 60rpx;
					}
				}
			}

			.oneSub {
				background: #f1f1f1;
				line-height: 60rpx;
				padding: 0 30rpx;

				view {
					font-weight: bold;

					&:last-of-type {
						font-family: "numberFont";
						letter-spacing: 2rpx;
						font-size: 32rpx;
					}
				}
			}
		}

		.twoBox {
			margin-top: 60rpx;
			border-radius: 10rpx;
			padding: 34rpx 30rpx 30rpx;
			box-shadow: 0 0 20rpx rgb(221, 221, 221);

			.twoItem {
				width: 100%;

				view {
					font-size: 28rpx;
					line-height: 42rpx;

					text {
						font-size: 32rpx;
						font-family: "numberFont";
						font-weight: bold;
						letter-spacing: 2rpx;
					}
				}
			}
		}

		.threeBox {
			padding: 60rpx 0;

			.threeItem {
				width: 48%;
				box-shadow: 0 0 20rpx rgb(221, 221, 221);
				border-radius: 10rpx;
				padding: 32rpx 0 35rpx;
				display: flex;
				align-items: center;
				justify-content: space-around;
				
				& text:last-child {
					display: block;
					font-size: 36rpx;
					font-family: "numberFont";
					font-weight: bold;
					padding-left: 10rpx;
				}
			}
		}
	}
</style>
